<%- include header%>
<%- include show%>
<hr>
<div class="row">
<div class="col-md-6">
<table class="table">
<script>
$(function(){
 


$(".add").click(function(){
var cprice=$(this).parent().parent().next().next().children("td.price").text();

var price=parseInt(cprice);

var order={};
order.pname=$(this).parent().prev().text();
order.amount=1;
order.state="watch";
order.pic=$(this).parent().prev().prev().children("img").attr("src");
order.price=price;

$.ajax({
type:"POST",
data:JSON.stringify(order),
contentType:'application/json',
url:"/cart"
});
$(this).prop('disabled', true);
});


});
</script>
				
					
<tbody>
<% posts.forEach(function(post,index){ 
var color=index%3;
var bcolor="";
if (color==0) bcolor="danger";
if(color==1) bcolor="success";
if(color==2) bcolor="warning";

%>
<div class="show">
<tr class=<%= bcolor%>>
<td rowspan=3><img width="120px" height="120px" src=<%= post.pic%> /></td>
<td class="pname" colspan=2><a href="p/<%= post.name%>"><%= post.name%></a></td>
<td  rowspan=3><button class="add btn btn-danger"><i class="fa fa-shopping-cart"></i>加入购物车</button>                 
		


</td>
</tr>
<tr class=<%= bcolor%>>
<td colspan=2><%= post.desp%></td>

</tr>

<tr class=<%= bcolor%>>
<td class="price"><%= post.price%><em>元</em></td>
<td class="infoshow">点击查看更多</td>
</tr>
</div>
<%})%>
</tbody>

</table>
</div>
</div>

<%- include nav%>
<%- include footer%>
